package com.task.poker.card;


import com.task.poker.card.services.PockerDeck;
import com.task.poker.card.services.PokerPlayer;
import com.task.poker.card.services.PokerSender;

import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Main class.
 * @author	JiDong
 * @create	November 14.2019
 */
public class Main {
    public static void main(String[] args) {
       PockerDeck pockerDeck = new PockerDeck();
       List<String> cards = pockerDeck.initializeCard();
       pockerDeck.shuffleCard();
       pockerDeck.display();

        System.out.println();
        CountDownLatch countDownLatch = new CountDownLatch(4);
        ExecutorService exec = Executors.newFixedThreadPool(4);
        exec.submit(new PokerSender(cards, pockerDeck, countDownLatch));
        exec.submit(new PokerPlayer(pockerDeck, countDownLatch));
        exec.submit(new PokerPlayer(pockerDeck, countDownLatch));
        exec.submit(new PokerPlayer(pockerDeck, countDownLatch));
        exec.shutdown();
        try {
            countDownLatch.await();
        } catch (InterruptedException E) {
        }
        System.out.println("game over...");
    }
}
